package com.eos.control.action.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.eos.business.service.SysActivityBusinessService;
import com.eos.common.tool.DataCacheUtil;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.SysActivty;
import com.eos.orm.mybatis.model.SysCustomer;
import com.hf.utils.PaginationBean;

public class ActivityListAction extends AbstractBaseAction {
	private static final long serialVersionUID = 4583489340567635786L;
	private String activityName;
	private String customerId;
	private String dealFlag;
	private Integer pageNum;
	private Integer numPerPage;
	private Integer totalCount;
	private List<SysActivty> activityList;
	private List<SysCustomer> customerList;

	public String getActivityName() {
		return activityName;
	}

	public void setActivityName(String activityName) {
		this.activityName = activityName;
	}

	public String getCustomerId() {
		return customerId;
	}

	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}

	public String getDealFlag() {
		return dealFlag;
	}

	public void setDealFlag(String dealFlag) {
		this.dealFlag = dealFlag;
	}

	public Integer getPageNum() {
		return pageNum;
	}

	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}

	public Integer getNumPerPage() {
		return numPerPage;
	}

	public void setNumPerPage(Integer numPerPage) {
		this.numPerPage = numPerPage;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	public List<SysActivty> getActivityList() {
		return activityList;
	}

	public List<SysCustomer> getCustomerList() {
		return customerList;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String execute() {
		try {
			if(pageNum == null || pageNum.intValue()==0) pageNum = 1;
			if(numPerPage == null || numPerPage.intValue() ==0) numPerPage = PAGE_SIZE;
			SysActivityBusinessService sabs = new SysActivityBusinessService();
			Map<String, String> map = new HashMap<String, String>();
			map.put("activty_name", activityName);
			map.put("page_size", numPerPage + "");
			map.put("cur_page", pageNum + "");
			map.put("deal_flag", dealFlag);
			map.put("customer_id", customerId);
			map.put("table_name", "sys_activty");
			PaginationBean pageBean = sabs.getSysActivtityList(map);
			totalCount = null != pageBean ? pageBean.getMaxcount() : 0;
			activityList = null != pageBean ? (List<SysActivty>)pageBean.getResultList() : null;
			
			List<SysCustomer> cList = DataCacheUtil.getAllSysCustomer();
			List<SysCustomer> rtnList = null;
			if(null != cList){
				rtnList = new ArrayList<SysCustomer>();
				for(SysCustomer c : cList){
					if("0".equals(c.getCustomerType())){
						rtnList.add(c);
					}
				}
				customerList = rtnList;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
}
